import { createHashRouter, Navigate } from 'react-router-dom'
import type { ComponentProps } from 'react'
import Layout from '@/layout'
import Login from '@/pages/login'
import Home from '@/pages/home'
import About from '@/pages/about'

// 全局路由
export const globalRouters = createHashRouter([
  // 对精确匹配"/login"，跳转Login页面
  {
    path: '/login',
    element: <Login />
  },
  {
    path: '/',
    element: <Layout />,
    children: [
      {
        path: '/home',
        element: <Home />
      },
      {
        path: '/',
        element: <Navigate to="/home" />
      },
      {
        path: '*',
        element: <Navigate to="/login" />
      },
      {
        path: '/about',
        element: <About />
      }
    ]
  }
])

/** 路由守卫 */
export function BeforeEntryRoute(props: any) {
  const isLogin = true
  if (isLogin) {
    return props.children
  } else {
    return <Navigate to="/login" />
  }
}
